import Vue from 'vue';
import VueResource from 'vue-resource';
// import LogPlugin from "./utils/log-plugin";
import App from './App';
import router from './router';
import store from './store';
import axios from 'axios';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-default/index.css';    // 默认主题
// import '../static/css/theme-green/index.css';       // 浅绿色主题
import "babel-polyfill";
import { API_PREFIX } from './config';
import tokenUtils from './utils/tokenUtils';
import Vodal from 'vodal';
// Vue.use(LogPlugin);

Vue.component(Vodal.name, Vodal);

Vue.use(ElementUI);
Vue.use(VueResource);
Vue.prototype.$axios = axios;
Vue.http.options.root = API_PREFIX;
Vue.http.interceptors.push(function (req, next) {
    //Vue.log.debug("Request >>>", req.method, req.url, 'params:' + JSON.stringify(req.params), 'body:' + JSON.stringify(req.body));
    console.log("Request >>>", req.method, req.url, 'params:' + JSON.stringify(req.params), 'body:' + JSON.stringify(req.body));
    next(function (res) {
        //Vue.log.debug("Response >>>", res.status, JSON.stringify(res.body));
        console.log("Response >>>", res.status, JSON.stringify(res.body));
        if (res.status == 401) {
            // TODO: go back to login page
            tokenUtils.resetToken();
            router.push('/login');
        }
    });
})
tokenUtils.autoLogin();

new Vue({
    router,
    store,
    render: h => h(App),
}).$mount('#app');